package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingPageVo;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingController
 * @Author wangwei
 * @Date 2024-08-23
 * */
/*服务项目完成*/
@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingController extends BaseController{
    @Autowired
    NursingProjectService nursingProjectService;

    /**
     *分页查询护理项目
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    public ResponseResult<NursingPageVo<NursingProject>> getNursingProjectInfo(
          @RequestParam(defaultValue = "") String name,
          @RequestParam(defaultValue = "1") Integer pageNum,
          @RequestParam(defaultValue = "10") Integer pageSize,
           Integer status
    ){
            log.info("接收请求参数为{},{},{},{}",name,pageNum,pageSize,status);
        NursingPageVo<NursingProject> pageVo = nursingProjectService.getNursingProjectInfo(name,pageNum,pageSize,status);
            return success(pageVo);
    }

    /**
     * 添加项目功能
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
            log.info("接收的前端信息{}",nursingProjectDto);
            nursingProjectService.addNursingProject(nursingProjectDto);
            return success();
    }

    /**
     * 根据ID获取护理项目
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getProjectInfoByID(@PathVariable Integer id){
        NursingProject nursingProject = nursingProjectService.getProjectInfoByID(id);
        return success(nursingProject);
    }

    /**
     * 更新护理项目信息
     * @param nursingProjectDto
     * @return
     */
    @PutMapping("/{id}")
    public ResponseResult updateProjectInfo(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("接收更新信息{}",nursingProjectDto);
        nursingProjectService.updateProjectInfo(nursingProjectDto);
        return success();
    }

    /**
     * 根据ID修改护理项目的状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        log.info("接收启用禁用信息id:{},status:{}",id,status);
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    /**
     * 根据ID删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteProjectByID(@PathVariable Long id){
        nursingProjectService.deleteProjectByID(id);
        return success();
    }

    /**
     * 获取所有的护理项目信息
     * @return
     */
    @GetMapping("/all")
    public ResponseResult getAllProjectInfo(){
            List<NursingProjectDto> list = nursingProjectService.getAllProjectInfo();
            return success(list);
    }
}
